package com.jc.oms.controller.supplier;

import com.jc.common.util.WebUtils;
import com.jc.ds.model.Supplier;
import com.jc.service.supplier.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 供应商
 * */
@SuppressWarnings("all")
@Controller
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @RequestMapping(value = "/querySupplierAll",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> querySupplierAll(HttpServletRequest request){
        Map<String,Object> result = new HashMap<String, Object>(){{
            put("code",10000);
        }};
        try {
            Map<String, Object> paramMap = WebUtils.ReadAsChars(request);
            Supplier supplier = WebUtils.mapToBean(paramMap, new Supplier());
            List<Supplier> suppliers = supplierService.queryAll(supplier);
            result.put("data",suppliers);
        } catch (UnsupportedEncodingException e) {
            result.put("msg",e.getLocalizedMessage());
            result.put("code",9999);
            e.printStackTrace();
        }
        return result;
    }
}
